<?php

namespace Common\Model;

class BookContentModel extends XuecheModel {

    protected $pk = 'article_id';
    protected $tableName = 'book_content';
    protected $fields = array(
            'article_id','content'
        );

    /**
     * 清空数据缓存
     *
     */
    public function ClearAllCache() {

    }

    //缓存设置
    protected $_useCacheType = 'file';
    protected $_catheTime = 0;

    public function Validate($data) {
        return true;
    }

    public function getContent($article_id){
        if($article_id > 0){
            return $this->where("`{$this->pk}` = '{$article_id}")->field('content')->find();
        }
    }

    //保存或修改conent
    public function saveContent($data){
        if($data['article_id'] > 0 && $data['content']){
            $where = "`{$this->pk}` = '{$data[$this->pk]}'";
            //$data['content'] = htmlentities($data['content']);
            if($this->where($where)->find()){
                unset($data['article_id']);
                return $this->where($where)->save($data);
            }else{
                return $this->add($data);
            }
        }
        p($data);
        return FALSE;
    }



}
